﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CityLife
{
    public partial class BudgetWindow : FloatableWindow
    {

        Dictionary<string, TextBox> IncomeFileds = new Dictionary<string, TextBox>();

        public BudgetWindow()
        {
            InitializeComponent();

            Transportation.ValueChanged += new System.Windows.RoutedPropertyChangedEventHandler<double>(Transportation_ValueChanged);
            Education.ValueChanged += new RoutedPropertyChangedEventHandler<double>(Education_ValueChanged);
            Police.ValueChanged += new RoutedPropertyChangedEventHandler<double>(Police_ValueChanged);
            HealthCare.ValueChanged += new RoutedPropertyChangedEventHandler<double>(HealthCare_ValueChanged);



            TransportationVal.Text = MainPage.Heart.City.Budget.Transportation.ToString();
            Transportation.Value = MainPage.Heart.City.Budget.Transportation;

            EducationVal.Text = MainPage.Heart.City.Budget.Education.ToString();
            Education.Value = MainPage.Heart.City.Budget.Education;

            PoliceVal.Text = MainPage.Heart.City.Budget.Police.ToString();
            Police.Value = MainPage.Heart.City.Budget.Police;

            HealthCareVal.Text = MainPage.Heart.City.Budget.HealthCare.ToString();
            HealthCare.Value = MainPage.Heart.City.Budget.HealthCare;



            IncomeFileds.Add("Residential1Val", ((TextBox)this.IncomeTabs.FindName("Residential1Val")));
            IncomeFileds.Add("Residential2Val", ((TextBox)this.IncomeTabs.FindName("Residential2Val")));
            IncomeFileds.Add("Residential3Val", ((TextBox)this.IncomeTabs.FindName("Residential3Val")));

            IncomeFileds["Residential1Val"].Text = MainPage.Heart.City.Budget.Residential.ToString();
   


            IncomeFileds.Add("Commercial1Val", ((TextBox)this.IncomeTabs.FindName("Commercial1Val")));
            IncomeFileds.Add("Commercial2Val", ((TextBox)this.IncomeTabs.FindName("Commercial2Val")));
            IncomeFileds.Add("Commercial3Val", ((TextBox)this.IncomeTabs.FindName("Commercial3Val")));

            IncomeFileds["Commercial1Val"].Text = MainPage.Heart.City.Budget.Commercial.ToString();
 


            IncomeFileds.Add("Industrial1Val", ((TextBox)this.IncomeTabs.FindName("Industrial1Val")));
            IncomeFileds.Add("Industrial2Val", ((TextBox)this.IncomeTabs.FindName("Industrial2Val")));
            IncomeFileds.Add("Industrial3Val", ((TextBox)this.IncomeTabs.FindName("Industrial3Val")));

            IncomeFileds["Industrial1Val"].Text = MainPage.Heart.City.Budget.Industrial.ToString();
   


         

 


 




            //ResidentialVal1.Text = MainPage.Heart.City.Budget.Residential.ToString();
            //Residential1.Value = MainPage.Heart.City.Budget.Residential;


            //CommercialVal.Text = MainPage.Heart.City.Budget.Commercial.ToString();
            //Commercial.Value = MainPage.Heart.City.Budget.Commercial;


            //IndustrialVal.Text = MainPage.Heart.City.Budget.Industrial.ToString();
            //Industrial.Value = MainPage.Heart.City.Budget.Industrial;
        }

        void HealthCare_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            HealthCareVal.Text = Math.Round(e.NewValue).ToString();
        }

        void Police_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            PoliceVal.Text = Math.Round(e.NewValue).ToString();
        }

        void Education_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            EducationVal.Text = Math.Round(e.NewValue).ToString();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {

            MainPage.Heart.City.Budget.Transportation = Convert.ToInt32(TransportationVal.Text);
            MainPage.Heart.City.Budget.Police = Convert.ToInt32(PoliceVal.Text);
            MainPage.Heart.City.Budget.Education = Convert.ToInt32(EducationVal.Text);
            MainPage.Heart.City.Budget.HealthCare = Convert.ToInt32(HealthCareVal.Text);

            MainPage.Heart.City.Budget.Residential = Convert.ToInt32(IncomeFileds["Residential1Val"].Text);
            //MainPage.Heart.City.Budget.Residential2 = Convert.ToInt32(IncomeFileds["Residential2Val"].Text);
            //MainPage.Heart.City.Budget.Residential3 = Convert.ToInt32(IncomeFileds["Residential3Val"].Text);

            MainPage.Heart.City.Budget.Commercial = Convert.ToInt32(IncomeFileds["Commercial1Val"].Text);
            //MainPage.Heart.City.Budget.Commercial2 = Convert.ToInt32(IncomeFileds["Commercial2Val"].Text);
            //MainPage.Heart.City.Budget.Commercial3 = Convert.ToInt32(IncomeFileds["Commercial3Val"].Text);

            MainPage.Heart.City.Budget.Industrial = Convert.ToInt32(IncomeFileds["Industrial1Val"].Text);
            //MainPage.Heart.City.Budget.Industrial2 = Convert.ToInt32(IncomeFileds["Industrial2Val"].Text);
            //MainPage.Heart.City.Budget.Industrial3 = Convert.ToInt32(IncomeFileds["Industrial3Val"].Text);

            

            //MainPage.Heart.City.Budget.Residential1 = this.IncomeTabs

           // MainPage.Heart.City.Budget.Residential = Convert.ToInt32(ResidentialVal.Text);
            //MainPage.Heart.City.Budget.Commercial = Convert.ToInt32(CommercialVal.Text);
           // MainPage.Heart.City.Budget.Industrial = Convert.ToInt32(IndustrialVal.Text);


            MainPage.Heart.SetDirty();

            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void Transportation_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
        {
            TransportationVal.Text = Math.Round(e.NewValue).ToString();
        }

        private void TransportationVal_TextChanged(object sender, TextChangedEventArgs e)
        {
            Transportation.Value =Convert.ToInt64( (sender as TextBox).Text);
        }

        private void HealthCareVal_TextChanged(object sender, TextChangedEventArgs e)
        {
            HealthCare.Value = Convert.ToInt64((sender as TextBox).Text);
        }

        private void EducationVal_TextChanged(object sender, TextChangedEventArgs e)
        {
            Education.Value = Convert.ToInt64((sender as TextBox).Text);
        }

        private void PoliceVal_TextChanged(object sender, TextChangedEventArgs e)
        {
            Police.Value = Convert.ToInt64((sender as TextBox).Text);
        }

       


        //private void Commercial_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        //{
        //    CommercialVal.Text = Math.Round(e.NewValue).ToString();
        //}

        //private void Industrial_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        //{
        //    IndustrialVal.Text = Math.Round(e.NewValue).ToString();
        //}


        private void SliderValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            string id = (sender as Control).Name;

            //get last char
          //  char lc = id[id.Length - 1];

           // id = id.Remove(id.Length-1);


            TextBox t = (TextBox)this.FindName(id + "Val");
            t.Text = Math.Round(e.NewValue).ToString();
        }


        private void TextVal_TextChanged(object sender, TextChangedEventArgs e)
        {

            string id = (sender as Control).Name;

            Slider t = (Slider)this.FindName(id.Replace("Val",""));          
            t.Value = Convert.ToInt64((sender as TextBox).Text);
        }


        private void ResidentialVal_TextChanged(object sender, TextChangedEventArgs e)
        {
           // Residential.Value = Convert.ToInt64((sender as TextBox).Text);
        }

        //private void CommercialVal_TextChanged(object sender, TextChangedEventArgs e)
        //{
        //    Commercial.Value = Convert.ToInt64((sender as TextBox).Text);
        //}

        //private void IndustrialVal_TextChanged(object sender, TextChangedEventArgs e)
        //{
        //    Industrial.Value = Convert.ToInt64((sender as TextBox).Text);
        //}
    }
}

